import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getSmsCodeService, goLoginService } from '@/apis/user'
import type { LoginData, LoginResponseData, UserInfo } from '@/apis/user/type'
export const useUserStore = defineStore(
  'doctor-user',
  () => {
    const dialogVisible = ref(false)

    // 获取验证码
    const smsCode = ref('')
    const getSmsCode = async (phone: string) => {
      const res = await getSmsCodeService(phone)
      smsCode.value = res.data
    }

    // 登录
    const userInfo = ref<UserInfo>({
      name: '',
      token: ''
    })
    const goLogin = async (data: LoginData) => {
      const res: LoginResponseData = await goLoginService(data)
      userInfo.value = res.data
    }

    return {
      dialogVisible,
      smsCode,
      getSmsCode,
      userInfo,
      goLogin
    }
  },
  {
    persist: true
  }
)
